class BytesArrayUtil {

    constructor(data){
        this.data=data;
        this.unit8Arr = new Uint8Array(this.data) ;
        this.encodedString = String.fromCharCode.apply(null, this.unit8Arr);
        this.decodedString = decodeURIComponent(escape((this.encodedString)));//没有这一步中文会乱码
    }
    toString  () {
        return this.encodedString;
    }
    toCnString () {
        return this.decodedString;
    }

    to10String () {
        return parseInt(this.data, 10);
    }
    static to10String (num) {
            return parseInt(num, 10);
    }
    static unit8ArrtoString(data){
        let unit8Arr = new Uint8Array(data) ;
        let encodedString = String.fromCharCode.apply(null, unit8Arr);
        let  decodedString = decodeURIComponent(escape((encodedString)));//没有这一步中文会乱码
        return encodedString;
    }
    static  bytesToInt(src, offset) {
    let v;
    v =   ((src[offset] & 0xFF)
        | ((src[offset+1] & 0xFF)<<8)
        | ((src[offset+2] & 0xFF)<<16)
        | ((src[offset+3] & 0xFF)<<24));
    return v;
}

    static intTobytes2(n){
        var c = [];

        for (var i = 0; i < 2; i++) {
            c[i] = n >> (8 - i * 8);

        }
        return c;
    }


    static unit8ArrtoInt(data){
        let int_=new Uint32Array(1);
        int_[0]= (data[3] & 0xFF)<<24;

        int_[0]=int_[0] | ((data[2] & 0xFF) <<16);

        int_[0]=int_[0] | ((data[1] & 0xFF) <<8);

        int_[0]=int_[0] | (data[0] & 0xFF);
        return int_
    }
}

